<template>
  <carousel :autoplay="true" :items="carouselNumber" :nav="false" :dots="false" :loop="true">
    <template slot="prev">
      <span class="prev leftprev" style="display:block !important;">
        <img src="@/assets/icons/leftact.png" class="runIcon" alt />
      </span>
    </template>
    <div v-for="(item, index) of imgList" :key="index" style="margin-top:-3px">
      <img class="swiperimg" :src="getImage(item.path)" />
      <div class="whiteaction">
        <div class="fontposition" :title="imgactionList[index]">{{imgactionList[index] }}</div>
      </div>
    </div>
    <template slot="next">
      <span class="next rightprev">
        <img src="@/assets/icons/righact.png" class="runIcon" alt />
      </span>
    </template>
  </carousel>
</template>
<script>
import carousel from "vue-owl-carousel";

export default {
  components: { carousel },
  data() {
    return {
      pcWidth: window.screen.width,
      timer: false,
      carouselNumber: 6,
      imgactionList: [
        "安徽庐江县洪涝灾害遥感监测图",
        "安徽省阜南县洪涝灾害遥感监测图",
        "安徽省阜阳市蒙洼蓄滞洪区水体面积变化监测图",
        "安徽省洪涝灾害遥感监测图（巢湖周边）",
        "安徽省洪涝灾害遥感监测图（淮河流域）",
        "甘肃省陇南市文县石鸡坝镇洪涝灾害遥感监测图",
        "江西鄱阳昌洲乡洪涝灾害遥感监测图",
        "江西省鄱阳湖遥感监测图",
        "江西省鄱阳湖周边水体面积变化",
        "江西省永修县三角圩、新建区新培圩洪涝灾害监测图",
        "四川省成都市洪涝灾害遥感监测图",
        "四川省平武县洪涝灾害遥感监测图",
        // "2020年平均降水量产品",
        // "2014全国归一化植被指数年均值",
        // "2015年全国叶面积指数年均值",
        // "2000年全国土地利用分布图",
        // "2015年全国叶面积指数年均值",
        // "2020年平均降水量产品",
        // "2014全国归一化植被指数年均值",
        // "2015年全国叶面积指数年均值",
        // "2000年全国土地利用分布图",
      ],
      imgList: [
        { path: "A1.jpg" },
        { path: "A2.jpg" },
        { path: "A3.jpg" },
        { path: "A4.jpg" },
        { path: "A5.jpg" },
        { path: "A6.jpg" },
        { path: "A7.jpg" },
        { path: "A8.jpg" },
        { path: "A9.jpg" },
        { path: "A10.jpg" },
        { path: "A11.jpg" },
        { path: "A12.jpg" },

        // { path: "111.png" },
        // { path: "333.png" },
        // { path: "444.png" },
        // { path: "555.png" },
        // { path: "666.png" },
        // { path: "111.png" },
        // { path: "333.png" },
        // { path: "444.png" },
        // { path: "555.png" },
      ],
    };
  },
  watch: {
    pcWidth(newval) {
      if (!this.timer) {
        this.pcWidth = val;
        this.timer = true;
        let that = this;
        setTimeout(function () {
          // that.screenWidth = that.$store.state.canvasWidth
          console.log(that.pcWidth);
          that.init();
          that.timer = false;
        }, 400);
      }
    },
  },
  created() {
    this.calculateScreenWidth();
  },
  mounted() {
    let that = this;
    window.onresize = () => {
      return (() => {
        that.pcWidth = window.screen.width;
      })();
    };
  },
  methods: {
    calculateScreenWidth() {
      this.pcWidth = window.screen.width;
      if (this.pcWidth >= 1920) {
        this.carouselNumber = 8;
        return;
      }
      if (this.pcWidth >= 1600) {
        this.carouselNumber = 5;
        return;
      }
      if (this.pcWidth >= 1536) {
        this.carouselNumber = 5;
        return;
      }
      if (this.pcWidth >= 1366) {
        this.carouselNumber = 4;
        return;
      }
      if (this.pcWidth >= 1280) {
        this.carouselNumber = 4;
        return;
      }
    },
    getImage(picName) {
      return require("@/assets/icons/caruseimge/data/" + picName);
    },
  },
};
</script>
<style scoped>
.swiperimg {
  height: 116px;
  /* width: 120px; */
}
.whiteaction {
  position: absolute;
  height: 28px;
  font-size: 1rem;
  margin-top: -29px;
  width: 190px;
  margin-left: 7px;
  background-color: rgba(0, 0, 0, 0.5);
  text-shadow: 1px 1px 1px #000;
}

.fontposition {
  line-height: 28px;
  font-size: 12px;
  text-align: center;
  color: #fff;
}

.leftprev {
  display: flex;
  float: left;
  height: 112px;
  width: 30px;
  margin-left: -32px;
  background: #dce4ed;
}

.rightprev {
  display: flex;
  float: right;
  height: 112px;
  width: 30px;
  margin-right: -35px;
  margin-top: -112px;
  background: #dce4ed;
}
.runIcon {
  margin-top: 40px;
  margin-left: 10px;
  width: 11px;
  height: 30px;
}
/* .swiperimg {
  height: 106px;
  width: 202px;
}
.owl-carousel .owl-item img {
  height: 125px;
  width: 250px;
}
.imgLeft {
  position: absolute;
  left: -46px;
  width: 30px;
  height: 104px;
  top: 3px;
  background-size: 80%;
  background: #dce4ed;
  cursor: pointer;
}

.imgRight {
  position: absolute;
  right: -22px;
  width: 30px;
  height: 104px;
  top: 3px;
  background-size: 80%;
  background: #dce4ed;
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
  cursor: pointer;
}
.whiteaction {
  position: absolute;
  height: 28px;
  font-size: 1rem;
  margin-top: -29px;
  width: 241px;
  margin-left: 7px;
  background-color: rgba(0, 0, 0, 0.5);
  text-shadow: 1px 1px 1px #000;
}

.fontposition {
    line-height: 28px;
    font-size: 16px;
    text-align: center;
    color: #fff;
}
.leftprev {
  display: flex;
  float: left;
  height: 120px;
  width: 30px;
  margin-left: 15px;
  background: #dce4ed;
}
.rightprev {
  display: flex;
  float: right;
  height: 120px;
  width: 30px;
  margin-right: 15px;
  margin-top: -120px;
  background: #dce4ed;
}
.runIcon {
  margin-top: 45px;
  margin-left: 5px;
  width: 20px;
  height: 30px;
} */
/* 轮播的媒体查询  */
@media (min-width: 998px) {
  .carouseSty {
    width: 742px;
  }
  .whiteaction {
    width: 177px;
    margin-left: 6px;
    /* 轮播item  4 */
  }
}
@media (min-width: 1366px) {
  .whiteaction {
    width: 198px;
    /* 轮播item  4 */
  }
}
@media (min-width: 1400px) {
  .whiteaction {
    width: 200px;
    /* 轮播item  4 */
  }
}
@media (min-width: 1600px) {
  .whiteaction {
    width: 204px;
    /* 轮播item  5 */
  }
}
@media (min-width: 1919px) {
  .whiteaction {
    width: 165px;
    /* 轮播item  6 */
  }
}
</style>
